﻿<Window x:Class="AmazonGlacierGUI.UI.Views.DownloadArchiveFromAmazonInventoryView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib"
        xmlns:AmazonGlacier="clr-namespace:AmazonGlacierGUI.Core.Helpers.AmazonGlacier;assembly=AmazonGlacierGUI.Core"
        xmlns:FWControls="clr-namespace:AmazonGlacierGUI.UI.Infrastructure.MVVMFramework.Controls"
        Title="Download archive" Height="320" Width="735" WindowStartupLocation="CenterScreen" ResizeMode="CanResize">
    <Window.Resources>
        <ObjectDataProvider x:Key="regionEnum"
       MethodName="GetValues" ObjectType="{x:Type System:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="AmazonGlacier:AmazonRegionEnum"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </Window.Resources>
    <Grid Margin="5">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
            </Grid.RowDefinitions>
            
            <StackPanel Grid.Row="0">
                <FWControls:ValidationSummary Margin="0,5,0,5" Loaded="ValidationSummary_Loaded"></FWControls:ValidationSummary>
                <!--<TextBlock HorizontalAlignment="Left" Text="Loading please wait..." Width="196" Visibility="{Binding IsLoading,Converter={StaticResource BooleanToVisibilityConverter}}"/>-->
            </StackPanel>
            <StackPanel Grid.Row="1">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition  Height="20"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="Save to"></TextBlock>
                    <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
                        <TextBox Width="348" TextWrapping="NoWrap" Text="{Binding SaveToPath,Mode=TwoWay,ValidatesOnDataErrors=True,NotifyOnValidationError=True}"></TextBox>
                        <Button Content="Browse" Height="21" Width="43" Command="{Binding BrowseFolderCommand}"></Button>
                    </StackPanel>
                </Grid>
                <Grid  Margin="0,5,0,0">
                    <Grid.RowDefinitions>
                        <RowDefinition  Height="20"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"></ColumnDefinition>
                        <ColumnDefinition Width="88"></ColumnDefinition>
                        <ColumnDefinition Width="465" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="Region"></TextBlock>
                    <ComboBox Grid.Column="1" ItemsSource="{Binding Source={StaticResource regionEnum}}"
                          SelectedItem="{Binding Region,Mode=TwoWay,ValidatesOnDataErrors=True,NotifyOnValidationError=True}" Width="348" HorizontalAlignment="Left" Grid.ColumnSpan="2"></ComboBox>
                </Grid>
                <Grid  Margin="0,5,0,0">
                    <Grid.RowDefinitions>
                        <RowDefinition  Height="20"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <TextBlock  Grid.Column="0" Text="Vault"></TextBlock>
                    <StackPanel  Orientation="Horizontal" Grid.Column="1">
                        <TextBox Text="{Binding Path=SelectedVault.VaultName,FallbackValue='',ValidatesOnDataErrors=True,NotifyOnValidationError=True}"  IsReadOnly="True" Width="199" Background="#FFF0F0F0"></TextBox>
                        <Button Content="Browse" Height="21" Width="43" Command="{Binding BrowseVaultCommand}" Margin="5,0,0,0"></Button>
                    </StackPanel>
                </Grid>              

                <StackPanel Margin="0,5,0,0">
                    <TextBlock Text="{Binding InventoryStatusMessage}" ></TextBlock>
                    <StackPanel Orientation="Horizontal">
                        <Button Content="Reset" Width="68"  Command="{Binding ResetCommand}"  Margin="0,0,5,0" Visibility="{Binding CanReset,Converter={StaticResource BooleanToVisibilityConverter}}"></Button>
                        <Button Content="Refresh" Width="68" Command="{Binding RefreshCommand}" Margin="0,0,5,0" Visibility="{Binding CanRefresh,Converter={StaticResource BooleanToVisibilityConverter}}"></Button>
                        <Button  Content="Request inventory" Width="103" Command="{Binding RequestInventoryCommand}" Visibility="{Binding CanRequestInventory,Converter={StaticResource BooleanToVisibilityConverter}}"></Button>
                    </StackPanel>
                </StackPanel>
                <TextBlock Text="{Binding InventoryLastLoadedMessage}"  Margin="0,5,0,0"></TextBlock>
            </StackPanel>
            <DockPanel    Margin="0,5,0,0" Grid.Row="2">
                <DataGrid x:Name="dg" Grid.Row="1" AutoGenerateColumns="False" ItemsSource="{Binding ArchiveDetails}"
                  Margin="0,5,0,0"  CanUserAddRows="False" CanUserDeleteRows="False">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Header="" CanUserResize="False">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox  IsChecked="{Binding IsSelected,Mode=TwoWay,ValidatesOnDataErrors=True,NotifyOnValidationError=True,UpdateSourceTrigger=PropertyChanged}"></CheckBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Header="Description" Binding="{Binding Description}" IsReadOnly="True"/>
                        <DataGridTemplateColumn Header="Save as" Width="200">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBox Text="{Binding SaveAsFileName,Mode=TwoWay,ValidatesOnDataErrors=True,NotifyOnValidationError=True,UpdateSourceTrigger=LostFocus}"></TextBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Header="Uploaded on"  Binding="{Binding UploadedOn}" IsReadOnly="True"/>
                        <DataGridTextColumn Header="Size" Binding="{Binding Size,Converter={StaticResource BytesToTextConverter}}" IsReadOnly="True"/>                        

                    </DataGrid.Columns>
                </DataGrid>
            </DockPanel>

            <StackPanel Orientation="Horizontal" Margin="150,10,0,0" Grid.Row="3">
                <Button Content="Download"  Height="22" Width="80" VerticalAlignment="Top"  HorizontalAlignment="Left" Command="{Binding DownloadCommand}"></Button>
                <Button Content="Delete"  Height="22" Width="80" Margin="5,0,0,0" VerticalAlignment="Top"  HorizontalAlignment="Left" Command="{Binding DeleteCommand}"></Button>
                <Button Content="Close"  Height="22" Width="80" Margin="5,0,0,0" VerticalAlignment="Top"  HorizontalAlignment="Left" Command="{Binding CloseCommand}"></Button>

            </StackPanel>

        </Grid>
        <Grid Grid.Row="0"  Grid.RowSpan="4"
              Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter }}">
            <Rectangle Opacity=".7" Fill="White">
            </Rectangle>
            <ProgressBar Height="15" Width="100"  IsIndeterminate="True" ></ProgressBar>
        </Grid>
    </Grid>
</Window>
